import {
  batchDemandConfirm,
  delDemandById,
} from '@/api/purchase-demand/supportDemandReceive';
import { info } from '@/common/utils/modal-promise';
import { Message } from '@arco-design/web-vue';

export const getRowBtnList = (type: string, chileType: string) => {
  const allBtn = {
    confirmationBtn: {
      name: '确认',
      type: '3',
      func: confirmation,
    },
    delBtn: {
      name: '删除',
      type: '4',
      func: del,
    },
    remarkBtn: {
      name: '备注',
      type: '1',
      func: () => {
        return Promise.resolve();
      },
    },
    detailBtn: {
      name: '详情',
      type: '2',
      func: () => {
        return Promise.resolve();
      },
    },
  };
  const btnlist = <any>{
    '11': [allBtn.confirmationBtn, allBtn.delBtn],
    '12': [allBtn.confirmationBtn, allBtn.delBtn, allBtn.detailBtn],
    '13': [],
    '21': [allBtn.confirmationBtn, allBtn.delBtn],
    '22': [allBtn.confirmationBtn, allBtn.delBtn, allBtn.detailBtn],
    '23': [],
    '31': [allBtn.confirmationBtn, allBtn.delBtn],
    '32': [allBtn.confirmationBtn, allBtn.delBtn, allBtn.detailBtn],
    '33': [],
    '41': [allBtn.confirmationBtn, allBtn.delBtn],
    '42': [allBtn.confirmationBtn, allBtn.delBtn, allBtn.detailBtn],
    '43': [],
    '51': [allBtn.confirmationBtn, allBtn.delBtn],
    '52': [allBtn.confirmationBtn, allBtn.delBtn, allBtn.detailBtn],
    '53': [],
  };
  return btnlist[`${type}${chileType}`];
};
// 确认
const confirmation = async (param: any) => {
  console.log('全部确认', param);
  await info({
    title: '您确定要确认当前所选的需求？',
    content: '',
    hideCancel: false,
  });
  const par = {
    id: param.record.id,
    requireNo: param.record.requireNo,
    materialCode: param.record.materialCode,
    functionType: param.functionType,
    classType: param.activeTab,
    queryType: param.activeRadio,
  };
  const res: any = await batchDemandConfirm(par);
  if (res.code === 200) {
    Message.success('确认成功');
  }
};
// 删除
const del = async (param: any) => {
  console.log('删除', param);
  await info({
    title: '您确定要删除当前所选的需求？',
    content: '',
    hideCancel: false,
  });
  const par = {
    id: param.record.id,
    requireNo: param.record.requireNo,
    materialCode: param.record.materialCode,
    functionType: param.functionType,
    classType: param.activeTab,
    queryType: param.activeRadio,
  };
  const res: any = await delDemandById(par);
  if (res.code === 200) {
    Message.success('删除成功');
  }
};

export default null;
